#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <linux/input.h>

int tx, ty;
int flag = 0;

int getPosition()
{
    // 打开触摸屏
    int touch = open("/dev/input/event0", O_RDWR);
    if (touch < 0)
    {
        printf("打开触摸板失败！\n");
    }
    else
    {
        printf("打开触摸板成功！\n");
    }
    // 触摸屏
    struct input_event tc;
    while (1)
    {
        read(touch, &tc, sizeof(tc));
        // 判断
        if (tc.type == EV_ABS)
        {
            if (tc.code == ABS_X)
            {
                tx = tc.value;
                flag++;
            }
            if (tc.code == ABS_Y)
            {
                ty = tc.value;
                flag++;
            }
        }
        if (flag == 2)
        {
            flag = 0;
            break;
        }
    }
    printf("(x=%d,y=%d)\n", tx, ty);
}
int main()
{
    while (1)
    {
        getPosition();
        if (tx <= 50 && tx > 0 && ty <= 50 && ty > 0)
        {
            break;
        }
    }
}